﻿#ifndef __PIECHART_H__
#define __PIECHART_H__

#include <QWidget>
#include <QPainter>
#include <QBrush>
#include <QPen>
#include <QPropertyAnimation>
#include <QMap>


class PieChart : public QWidget
{
	Q_OBJECT
private:
	//指标数据
	QMap<QString, double> chart_value;
	//指标颜色
	QMap<QString, QColor> chart_color;
	//起点角度
	double start_angle;
	//覆盖角度
	double cover_angle;
	//占比总和（在添加数据时同步计算，避免在每次绘制时统计）
	double total_value;
	//内圈半径
	int i_radius;
	//外圈半径
	int o_radius;
	//偏移增量
	int m_offset;
	//旋转动画
	QPropertyAnimation* rotate_animation;
	//偏移动画
	QPropertyAnimation* offset_animation;
public:
	explicit PieChart(QWidget* parent = nullptr);
	void addData(const QString& desc, double value, const QColor& color);
protected:
	void paintEvent(QPaintEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
};


#endif // !__PIECHART_H__
